package com.pet.server.ext.action.task;

import java.util.Date;
import java.util.List;

import net.sf.json.JSONObject;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.BeanToJson;
import com.pet.server.ext.Result;
import com.pet.server.ext.constants.BaseAttribute;
import com.pet.server.ext.constants.Status;
import com.pet.server.ext.data.TaskInfo;
import com.pet.server.ext.data.UserTask;
import com.pet.server.ext.data.UserTaskDaily;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.DateUtil;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;

public class Info extends ActionBase{

	private String date;

	public Info(){
		 needCheckAuth =true;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		date = DateUtil.getFormatDate(new Date(), "yyyy-MM-dd");
	}
	
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
		List<TaskInfo> normal = userService.queryUserTaskInfo(user.user_id, Status.TaskType.normal.toString());//(user.user_id);
		List<TaskInfo> daily = userService.queryTaskDaily(user.user_id, DateUtil.getFormatDate(new Date(), "yyyy-MM-dd"), Status.TaskType.daily.toString());//(user.user_id, Status.TaskType.normal.toString());//(user.user_id);
		for(TaskInfo task:normal){
			task.setIs_done(task.task_time==task.done_time?BaseAttribute.LOGIC_TRUE:BaseAttribute.LOGIC_FALSE);
		}
		for(TaskInfo task:daily){
			task.setIs_done(task.task_time==task.done_time?BaseAttribute.LOGIC_TRUE:BaseAttribute.LOGIC_FALSE);
		}
		//UserTaskDaily utd = userService.findDailyTask(user.user_id, );
		Result result = new Result();
		JSONObject data = new JSONObject();
		data.put("normal", BeanToJson.listTojson(normal,"id"));
		data.put("daily",  BeanToJson.listTojson(daily,"id"));
		result.put("data", data);
	    return result;
	}
}
